home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / CAGDEXTR.C < prev    next >
C/C++ Source or Header  |  1991-05-18  |  3KB  |  93 lines

  1. /******************************************************************************
  2. * CagdEXTR.c - Extrusion operator out of a given profile and a direction vec. *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Mar. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #ifdef __MSDOS__
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <alloc.h>
  11. #endif /* __MSDOS__ */
  12.  
  13. #include "cagd_loc.h"
  14.  
  15. /******************************************************************************
  16. * Constructs an extrusion surface in the Vector direction for the given       *
  17. * profile curve. Input curve be either a Bspline or a Bezier curve and the    *
  18. * resulting output surface will be of the same type.                  *
  19. ******************************************************************************/
  20. CagdSrfStruct *CagdExtrudeSrf(CagdCrvStruct *Crv, CagdVecStruct *Vec)
  21. {
  22.     CagdSrfStruct *Srf;
  23.     int i, j,
  24.     MaxCoord = CAGD_NUM_OF_PT_COORD(Crv -> PType),
  25.     Len = Crv -> Length;
  26.     CagdPointType
  27.     PType = Crv -> PType;
  28.     CagdBType
  29.     IsNotRational = !CAGD_IS_RATIONAL_CRV(Crv);
  30.     CagdRType **SrfPoints,
  31.     **CrvPoints = Crv -> Points,
  32.     *Dir = Vec->Vec;
  33.  
  34.     switch (PType) {
  35.     case CAGD_PT_P2_TYPE:
  36.         PType = CAGD_PT_P3_TYPE;
  37.         break;
  38.     case CAGD_PT_E2_TYPE:
  39.         PType = CAGD_PT_E3_TYPE;
  40.         break;
  41.     case CAGD_PT_P3_TYPE:
  42.     case CAGD_PT_E3_TYPE:
  43.         break;
  44.     default:
  45.         FATAL_ERROR(CAGD_ERR_UNSUPPORT_PT);
  46.         break;
  47.     }
  48.  
  49.     switch (Crv -> GType) {
  50.     case CAGD_CBEZIER_TYPE:
  51.         Srf = BzrSrfNew(Len, 2, PType);
  52.         break;
  53.     case CAGD_CBSPLINE_TYPE:
  54.         Srf = BspSrfNew(Len, 2, Crv -> Order, 2, PType);
  55.         GEN_COPY(Srf -> UKnotVector, Crv -> KnotVector, sizeof(CagdRType) *
  56.                                  (Len + Crv -> Order));
  57.         Srf -> VKnotVector[0] = Srf -> VKnotVector[1] = 0.0;
  58.         Srf -> VKnotVector[2] = Srf -> VKnotVector[3] = 1.0;
  59.         break;
  60.     case CAGD_CPOWER_TYPE:
  61.         FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  62.         return NULL;
  63.     default:
  64.         FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  65.         return NULL;
  66.     }
  67.  
  68.     /* Copy the control mesh - first row is exactly the same as the curve    */
  69.     /* while second one is the same as first one translated by Vec.          */
  70.     SrfPoints = Srf -> Points;
  71.  
  72.     for (i = IsNotRational; i <= MaxCoord; i++)               /* First row. */
  73.     GEN_COPY(SrfPoints[i], CrvPoints[i],
  74.          sizeof(CagdRType) * Len);
  75.  
  76.     /* Make a copy of the Second row do we can "work" on it. */
  77.     for (i = IsNotRational; i <= MaxCoord; i++)              /* Second row. */
  78.     GEN_COPY(&SrfPoints[i][Len], CrvPoints[i],
  79.          sizeof(CagdRType) * Len);
  80.  
  81.     /* If the curve has lesser dimension (i.e. was 2D), Add zeros. */
  82.     for (i = MaxCoord + 1; i <= 3; i++)
  83.     for (j = 0; j < Len * 2; j++)
  84.         SrfPoints[i][j] = 0.0;
  85.  
  86.     for (i = 1; i <= 3; i++)            /* Translate the second row. */
  87.     for (j = Len; j < Len * 2; j++)
  88.         SrfPoints[i][j] += IsNotRational ? Dir[i - 1] :
  89.                            Dir[i - 1] * SrfPoints[W][j];
  90.  
  91.     return Srf;
  92. }
  93.